import produce from 'immer';
import { createAction } from '../utils';
import * as dataInfoService from '../services/dataInfo';

export default {
  namespace: 'dataInfo',
  state: {
    currentDataInfo:{},
    currentPoiInfo:{},
    allMigrationInfo:{}
  },
  reducers: {
    //=================================
    updateState(state, { payload }) {
      return { ...state, ...payload }
    },
    //=================================
  },
  effects: {
    *getByDataCode({ payload: { dataId }, onComplete }, { call,put }) {
      // const { status, data } = yield call(dataInfoService.getByDataCode, { dataId });
      // if(status){
      //   yield put(createAction('updateState')({ currentDataInfo: data?data:{} }));
      // }
    },
    *getPoiAddress({ payload: { searchContent }, onComplete }, { call,put }) {
      const { status, data } = yield call(dataInfoService.getPoiAddressBySearchContent, { searchContent });
      if(status){
        console.log(data)
        yield put(createAction('updateState')({ currentPoiInfo: data }));
      }
    },
    *getMigrationInfo({ payload: {  }, onComplete }, { call,put }) {
      const { status, data } = yield call(dataInfoService.getMigrationInfo, { });
      if(status){
        console.log(data.content)
        yield put(createAction('updateState')({ allMigrationInfo: data.content }));
      }
    }
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {

      })
    }
  }
}
